package com.example.networklab.mq.listener;

import com.example.networklab.constants.MQConstants;
import com.example.networklab.mq.dto.TaskCheckMQDTO;
import com.example.networklab.mq.dto.TaskScoreMQDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

//@Component
//@RequiredArgsConstructor
//@Slf4j
//public class TaskCheckListener {
//    private final RabbitTemplate rabbitTemplate;
//
//    @RabbitListener(queuesToDeclare = @Queue(value = MQConstants.TASK_CHECK_QUEUE_NAME))
//    public void listenTaskCheck(TaskCheckMQDTO taskCheckMQDTO) {
//        log.info("收到队列名为{}消息:[{}]", MQConstants.TASK_CHECK_QUEUE_NAME, taskCheckMQDTO);
//        try {
//            Thread.sleep(5000);
//        } catch (InterruptedException e) {
//            log.info("task.check消息处理失败:[{}]", taskCheckMQDTO);
//        }
//        //发送分数
//        TaskScoreMQDTO taskScoreMQDTO = new TaskScoreMQDTO();
//        taskScoreMQDTO.setId(taskCheckMQDTO.getId());
//        //Math.random() [0,1)
//        taskScoreMQDTO.setScore((int) (Math.random() * 100));
//        rabbitTemplate.convertAndSend(MQConstants.TASK_SCORE_QUEUE_NAME, taskScoreMQDTO);
//    }
//}
